/*
 * @Author: PU-TONG 1424838093@qq.com
 * @Date: 2023-06-29 03:09:03
 * @LastEditors: PU-TONG 1424838093@qq.com
 * @LastEditTime: 2023-06-29 06:46:13
 * @FilePath: /openharmony/device/board/isoftstone/qihang/app/My_pro/src/app_nfc.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "cmsis_os2.h"
#include "iot_errno.h"
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_i2c.h"
#include "nfc.h"
#include "ohos_init.h"
#include "app_log.h"

const static char *TAG = "app_nfc.c";

#define TEXT "IKUN INKUN.............."
#define WEB "openharmony.cn"

#define WIFI_IOT_IO_FUNC_GPIO_0_I2C1_SDA 6
#define WIFI_IOT_IO_FUNC_GPIO_1_I2C1_SCL 6
#define WIFI_IOT_I2C_IDX 0
#define WIFI_IOT_I2C_BAUDRATE 400000
#define TASK_DELAY_1S 1000000

/**
 * @brief i2c_nfc_test_task
 *
 */
void i2c_nfc_test_task(void)
{
    uint8_t ret;

    // GPIO_0 multiplexed to I2C1_SDA
    IoTGpioInit(0);
    IoTGpioSetFunc(0, WIFI_IOT_IO_FUNC_GPIO_0_I2C1_SDA);

    // GPIO_1 multiplexed to I2C1_SCL
    IoTGpioInit(1);
    IoTGpioSetFunc(1, WIFI_IOT_IO_FUNC_GPIO_1_I2C1_SCL);

    // baudrate: 400kbps
    IoTI2cInit(WIFI_IOT_I2C_IDX, WIFI_IOT_I2C_BAUDRATE);

    MY_LOGI(TAG,"I2C Test Start\n");

    ret = storeText(NDEFFirstPos, (uint8_t *)TEXT);
    if (ret != 1)
    {
        MY_LOGI(TAG,"NFC Write Data Falied :%d \n", ret);
    }
    ret = storeUrihttp(NDEFLastPos, (uint8_t *)WEB);
    if (ret != 1)
    {
        MY_LOGI(TAG,"NFC Write Data Falied :%d \n", ret);
    }
    while (1)
    {
        MY_LOGI(TAG,"Please use the mobile phone with NFC function close to the development board!\n");
        usleep(TASK_DELAY_1S);
    }
}
